﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Orange.Logistics.Models;
using System.Data.Objects.SqlClient;

namespace Orange.Logistics.Services {
    public interface IVenueService : IBaseService<VenueStaff> {


        IQueryable<dynamic> GetGrid();
    }
    public class VenueStaffService : BaseService<VenueStaff>, IVenueService {
        public IQueryable<dynamic> GetGrid() {
            var query = from v in db.VenueStaffs
                        join s in db.Stores
                             on v.Storeid.Trim() equals SqlFunctions.StringConvert((double)s.Storeid).Trim() into stor
                        from vs in stor.DefaultIfEmpty()
                        join j in db.Jobs
                             on v.Jobsid.Trim() equals SqlFunctions.StringConvert((double)j.Id).Trim() into job
                        from vj in job.DefaultIfEmpty()
                        select new {
                            Id = v.Id,
                            Contactor = v.Contactor,
                            Sexs = v.Sexs,
                            Birthdate = v.Birthdate,
                            Idcard = v.Idcard,
                            Phone = v.Phone,
                            Storeid = vs == null ? "" : vs.Names,
                            Storein = v.Storein,
                            Storeout = v.Storeout,
                            Jobsid = vj == null ? "" : vj.Name

                        };

            return query;
        }
    }
}